#pragma once
#include "const.h"
#include "proto/message.grpc.pb.h"
#include <grpcpp/grpcpp.h>

using grpc::Server;
using grpc::ServerBuilder;
using grpc::ServerContext;
using grpc::Status;
using message::GetChatServerReq;
using message::GetChatServerRsp;
using message::StatusService;

struct ChatServer
{
	std::string host;
	std::string port;
	std::string name;
	int con_count;
	ChatServer() :host(""), port(""), name(""), con_count(0) {};
	ChatServer(const ChatServer& cs) :host(cs.host), name(cs.name), port(cs.port), con_count(cs.con_count) {};
	ChatServer& operator=(const ChatServer& cs) {
		if (this == &cs)
		{
			return *this;
		}
		host = cs.host;
		port = cs.port;
		name = cs.name;
		con_count = cs.con_count;
		return *this;
	};
};
class StatusServiceImpl final: public  message::StatusService::Service
{
public:
	StatusServiceImpl();
	grpc::Status GetChatServer(ServerContext* context, const GetChatServerReq* request,
		GetChatServerRsp* reply) override;
	grpc::Status Login(ServerContext* context, const message::LoginReq* request, message::LoginRsp* reply) override;
private:
	ChatServer getChatServer();
	void insertToken(int uid,std::string token);
	std::unordered_map<std::string, ChatServer> _servers;
	int _server_index;
	std::mutex _mtx;
};

